package com.atguigu.yygh.hosp.mongo;


import com.atguigu.yygh.common.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mongo2")
public class TestMongo2 {

    @Autowired
    UserRepository userRepository;

    //查询所有
    @ApiOperation("查询所有")
    @GetMapping("/findAll")
    public Result findAll() {
        List<User> user = userRepository.findAll();
        System.out.println("user = " + user);
        return Result.ok().data("user",user);
    }


    //添加
    @ApiOperation("添加")
    @PostMapping("/create")
    public Result create() {
        User user = new User();
        user.setName("飞飞");
        user.setAge(20);
        user.setEmail("666@.com");
        User u = userRepository.save(user);
        return Result.ok().data("user",u);
    }
}
